package com.correo.vista.client.database;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;


public class DataBaseClient {
	public static final String USER="sa";
	public static final String PASSWORD="123456";		
	public final static String URL = "jdbc:sqlserver://10.0.0.102:1433";
    public final static String DRIVER = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
    
    private Connection   		  connection;   	//variable de conexion
    
	public DataBaseClient(){
		try {
			if(connection==null || connection.isClosed())
				getConnection();
		} catch (SQLException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}catch (Exception e) {
			e.printStackTrace();
		}
	}
	
    public void connection() throws ClassNotFoundException, SQLException{
        Class.forName(DRIVER);
        connection = DriverManager.getConnection(URL,USER,PASSWORD);        
    }
    
    public Connection getConnection() throws SQLException, ClassNotFoundException{
    	if (connection == null || connection.isClosed()){
			connection();
		}
    	return connection;
    }
        

}
